<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2019/11/22
 * Time: 9:58
 */

namespace app\controllers;


use app\utils\Com;
use yii\web\Controller;

class CurlController extends Controller
{

    public $enableCsrfValidation = false;
    public function actionIndex(){
        $this->layout = false;
        $str = Com::getStr();

        return $this->render("index",[
            'str' => $str
        ]);
    }

    public function actionGet(){
        $json = \Yii::$app->request->post("value");
        $arr = json_decode($json , true);

        foreach ($arr as $k => &$vo){
            foreach ($vo as &$item){
                $item['num'] = ($k+1);
                unset($item['href']);
            }
        }
        echo json_encode($arr);exit();
    }


    public function actionDo(){
        $this->layout = false;
        $str = Com::getStr2();
        preg_match_all('/(.+)\\n/',$str,$out);
        $arr = [];
        foreach ($out[1] as $k => $vo){
            if($k ==0){
                continue;
            }
            preg_match_all('/(\S+)/',$vo , $u);
            $item = [];
            $item['id'] = $u[1][0];
            $item['word'] = $u[1][1];
            $item['cat'] = $u[1][2];
            $item['num'] = $u[1][3];
            $item['pinyin'] = '';
            if(isset($u[1][4])){
                $item['pinyin'] .= $u[1][4];
            }
            if(isset($u[1][5])){
                $item['pinyin'] .= ' '.$u[1][5];
            }
            if(isset($u[1][6])){
                $item['pinyin'] .= ' '.$u[1][6];
            }

            $arr[] = $item;
        }

        echo json_encode($arr);exit();
    }

    public function actionTest(){
        $str = 'addss()85411addf';
        if(preg_match('/\((\d*)\)/',$str,$out)){
            echo "匹配到:{$out[1]}";
        }else{
            echo "没有匹配到";
        }
    }


}